package model

type SearchEngines struct {
	ID uint `gorm:"primary_key;AUTO_INCREMENT" json:"id" form:"id"`

	CategoryID uint32 `gorm:"default:0" form:"category_id" binding:"required" json:"category_id"`
	Name       string `gorm:"type:text" form:"name" binding:"required" json:"name"`
	URI        string `gorm:"type:text" form:"uri" binding:"required" json:"uri"` // %s 代替搜索关键词
}

func (m *SearchEngines) Add() (id uint, err error) {
	err = db.Create(&m).Error
	if err == nil {
		id = m.ID
	}
	return
}

func (m *SearchEngines) Update() (err error) {
	err = db.Omit("created_at").Model(SearchEngines{}).Where("id=?", m.ID).Updates(m).Error
	return
}

func DeleteSearchEngines(id uint) (err error) {
	err = db.Where("id=?", id).Delete(&SearchEngines{}).Error
	return
}
